﻿using UnityEngine;

public class PlayerWallSlide:PlayerStateBase
{
    public PlayerWallSlide(ControllerBase controller, StateMachineBase stateMachine, string stateName,string 
        animatorParameter) 
        : base(controller, stateMachine, stateName,animatorParameter)
    {
    }

    public override void Enter()
    {
        base.Enter();
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();
        if (Input.GetKeyDown(KeyCode.Space))
        {
            stateMachine.ChangeState(Setting.wallJump);
            return;
        }
        if (controller.isGround)//贴着地面
        {
            stateMachine.ChangeState(Setting.idle);
            return;
        }

        if (!controller.isWall)//没有贴墙
        {
            stateMachine.ChangeState(Setting.air);
            return;
        }
        
        //自动脱离墙
        if (SelfController.moveX!=0&&SelfController.moveX!=controller.faceDir)
        {
            stateMachine.ChangeState(Setting.idle);
            return;
        }
        
        //如果y轴速度小于0，则继续保持缓慢滑行
        if (SelfController.moveY>0)
        {
            controller.SetVelocity(new Vector2(0,controller.GetVelocity().y*0.7f));
        }else
        {
            controller.SetVelocity(new Vector2(0, controller.GetVelocity().y));
        }
    }
}